package com.cgt.day15;

import org.junit.Test;
public class test1 {
    @Test
    public void test11(){
        int[] array = {1,2,4,8,16,32,64};
        System.out.println(searchtarget(array,1));
        System.out.println(searchtarget(array,2));
        System.out.println(searchtarget(array,4));
        System.out.println(searchtarget(array,8));
        System.out.println(searchtarget(array,16));
        System.out.println(searchtarget(array,31));
    }

    public int searchtarget(int[] array,int target){
        int left = 0;
        int right = array.length;
        while (left < right){
            int mid = (left + right) / 2;
            if(target < array[mid]){
                right = mid;
            } else if(array[mid] < target){
                left = mid + 1;
            } else {
                return mid;
            }
        }
        return -1;
    }
}
